package com.graducationdesign.springboot.controller.Student;

import com.graducationdesign.springboot.entities.Administrator.GraducationDesignListMoudle.VoiceMessage;
import com.graducationdesign.springboot.entities.Administrator.PersonnalInformationMoudle.Student;
import com.graducationdesign.springboot.mapper.VoiceMessageMapper;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Mr.zhneg
 * @create 2020-02-02-21:16
 */
@Controller
public class MyNewsForStuController {
    org.slf4j.Logger logger=  LoggerFactory.getLogger(getClass());

    @Autowired
    VoiceMessageMapper voiceMessageMapper;

    @GetMapping("/mynewsforstu")
    public String list(HttpServletRequest request,Map<String,Object> map){

        logger.info("我的消息查看：");
        Object name=request.getSession().getAttribute("loginUser");
        List<VoiceMessage> names=voiceMessageMapper.getMessageByReceiveName(name);
        List<VoiceMessage> receivename=voiceMessageMapper.getMessageBySendName(name);

        map.put("name",names);
        map.put("receivenames",receivename);
        return "Student/personnalMoudle/mynews";
    }

    //    进入添加学生消息页面
    @GetMapping ("/sendinformationforstu")
    public String toAddPage(){

        return "Student/personnalMoudle/sendnews";
    }

    @PostMapping("/sendinformationforstu")
    public String add(VoiceMessage voiceMessage){

        logger.info("添加操作：发送信息。。"+voiceMessage);
        //保存数据操作
        voiceMessage.setData(new Date());
        voiceMessageMapper.addnews(voiceMessage);
//        return "redict:/mynewsforstu";
        return "Student/personnalMoudle/mynews";

    }


}
